<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>iMeYun.com_跨境电商ERP</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../../start/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../../start/layui/css/jquery-labelauty.css" media="all">
    <script src="../../../../start/common.js"></script>
    <script src="../../../../start/layui/layui.js"></script>
    <script src="../../../../start/layui/lay/modules/jquery.js"></script>
</head>
<body>

<div class="layui-form layui-tab-item layui-show" style="width:auto;">
    <div class="layui-card">
        <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md6">
                <form class="layui-form" action="" style="margin-top: 5%;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">方法名称:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <select id="methodName" name="methodName" lay-verify="required" lay-search >

                            </select>
                        </div>
                        <!--<div class="layui-form-mid layui-word-aux">-->
                        <!--天，几天一次，*表示每天-->
                        <!--</div>-->
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发件人邮箱:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="text" id="srcEmail" name="srcEmail" placeholder="请输入" lay-verify="required|email" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱密码:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="password" id="srcEmailPassword" name="srcEmailPassword" placeholder="请输入" lay-filter="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">收件人邮箱:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="text" id="targetEmail" name="targetEmail" placeholder="请输入" lay-verify="required|email" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">任务组:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="text" id="jobGroup" name="jobGroup" placeholder="请输入" lay-filter="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">任务名称:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="text" id="jobName" name="jobName" placeholder="请输入" lay-filter="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">任务规则:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="text" id="cronExpression" name="cronExpression" placeholder="请输入" lay-filter="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发件标题:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <input type="text" id="subject" name="subject" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发件内容:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <textarea placeholder="请输入任意内容" id="content" name="content" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">描述:</label>
                        <div class="layui-input-block" style="margin-right: 8%;">
                            <textarea placeholder="请输入内容" id="description" name="description" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <!-- <div class="layui-form-item">
                         <label class="layui-form-label">Before:</label>
                         <div class="layui-input-inline">
                             <input type="text" class="layui-input" id="quartzTaskAddTargetDayCreatedBefore" lay-verify="required" name="quartzTaskAddTargetDayCreatedBefore" placeholder="HH:mm:ss" autocomplete="off">
                         </div>
                         <div class="layui-form-mid layui-word-aux">
                             同步订单的起始时间
                         </div>
                     </div>
                     <div class="layui-form-item">
                         <label class="layui-form-label">After:</label>
                         <div class="layui-input-inline">
                             <select id="quartzTaskAddTargetDayCreatedAfter" name="quartzTaskAddTargetDayCreatedAfter" lay-verify="required" lay-search ></select>
                         </div>
                         <div class="layui-form-mid layui-word-aux">
                             同步订单的时间范围
                         </div>
                     </div>
                     <div class="layui-form-item">
                         <label class="layui-form-label">AfterUnit:</label>
                         <div class="layui-input-inline">
                             <select id="quartzTaskAddTargetDayCreatedAfterUnit" name="quartzTaskAddTargetDayCreatedAfterUnit" lay-verify="required" lay-search >
                                 <option value="天">天</option>
                             </select>
                         </div>
                         <div class="layui-form-mid layui-word-aux">
                             同步订单的时间范围单位
                         </div>
                     </div>-->
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="quartzTaskRuleSumbit">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

</body>
</html>
<script>
    layui.use(['form','jquery','laydate'],function () {
        var $ = layui.$;
        var form=layui.form;
        var laydate = layui.laydate;

        var quartzTaskData = layui.data('quartzTaskData').data;


//        //限定可选时间
//        laydate.render({
//            elem: '#quartzTaskAddTargetDayCreatedBefore'
//            ,type: 'time'
//            ,btns: ['clear', 'confirm']
//        });

        $(function () {
            $("#srcEmail").val(quartzTaskData.srcEmail);
            $("#srcEmailPassword").val(quartzTaskData.srcEmailPassword);
            $("#targetEmail").val(quartzTaskData.targetEmail);
            $("#jobGroup").val(quartzTaskData.jobGroup);
            $("#jobName").val(quartzTaskData.jobName);
            $("#cronExpression").val(quartzTaskData.cronExpression);
            $("#subject").val(quartzTaskData.subject);
            $("#content").val(quartzTaskData.content);
            $("#description").val(quartzTaskData.description);
        })

        $.ajax({
            url:'../../../../start/json/mail/select/methodNameSelect.json',
            type:'get',
            data:{},
            dataType:'json',
            success:function (data) {
                $.each(data.data,function (i,d) {
                    var opt = "<option value='"+d.value+"'>"+d.value+"</option>";
                    $("#methodName").append(opt);
                });
                form.render('select');
            }

        });

        form.on('submit(quartzTaskRuleSumbit)', function(data){
            updatequartzTaskRule(data.field);
            return false;
        });

        function updatequartzTaskRule(quartzTaskRuleData){
            quartzTaskRuleData.id=quartzTaskData.id;
            $.ajax({
                url:urll+'/mail/task/updateJob',
                type:'post',
                dataType:'json',
                data:{
                    'access_token': layui.data('layuiAdmin').access_token,
                    quartzTaskRuleData:JSON.stringify(quartzTaskRuleData)
                },
                async:false,
                success:function (data) {
                    if(data.code==0){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                    } else if(data.code==500){
                        layer.msg(data.msg);
                    }else{
                        layer.msg("创建失败");
                    }
                }
            });
        }

    });

</script>